
package apibasej.http;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import apibasej.basic.config.ConfigManager;


/**
 * http://code.google.com/p/apibasej/
 * 
 * @author Julio Azevedo Lessa - apibasej@gmail.com
 * 
 */
public class Field extends ConfigManager {

	private String name = null;
	private String value = null;

	/**
	 * Creates a new FormInputField.
	 * 
	 * @param name The name of the input field.
	 * @param value The value of the input field.
	 */
	public Field(String name, String value) {
		this.name = name;
		this.value = value;
	}

	/**
	 * Returns the name of the input field.
	 * 
	 * @return The name of the input field.
	 */
	public String getName() {
		return name;
	}

	/**
	 * Returns the value of the input field.
	 * 
	 * @return The value of the input field.
	 */
	public String getValue() {
		return value;
	}

	@SuppressWarnings("deprecation")
	public String getValueEncoded(){
		try {
			return URLEncoder.encode(getValue(),getProp(CHARSET));
		} catch (UnsupportedEncodingException e) {
			return URLEncoder.encode(getValue());
		}
	}
	
	/**
	 * Sets the name of the input field.
	 * 
	 * @param name The name of the input field.
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Sets the value of the input field.
	 * 
	 * @param value The value of the input field.
	 */
	public void setValue(String value) {
		this.value = value;
	}

}
